package scalafx.scene.web

import javafx.scene.{web => jfxsc}
import scalafx.Includes._
import scalafx.util.SFXDelegate
import collection.JavaConversions._
import scalafx.scene.control.Control
import scalafx.scene.Parent
import javafx.scene.web.WebEvent
import javafx.event.EventHandler
import javafx.geometry.Rectangle2D
import javafx.util.Callback
import javafx.scene.web.PopupFeatures
import javafx.scene.web.WebEngine
import javafx.scene.web.PromptData

object WebView {
  implicit def sfxAccordion2jfx(v: WebView) = v.delegate
}

class WebView(override val delegate:jfxsc.WebView = new jfxsc.WebView) extends Parent with SFXDelegate[jfxsc.WebView] {
      
  def width = delegate.prefWidthProperty
  def width_= (v: Double) { width() = v}
  
  def height = delegate.prefHeightProperty
  def height_= (v: Double) { height() = v}
  
  /* Properties of the asociated WebEngine */
  private val engine = delegate.getEngine
  
  def location = engine.locationProperty
  def location_= (v: String) { engine.load(v) }
  
  def title = engine.titleProperty
  
  def document = engine.documentProperty
  
  def onAlert = engine.onAlertProperty
  def onAlert_= (v: EventHandler[WebEvent[String]]) { onAlert() = v}

  def onStatusChanged = engine.onStatusChangedProperty
  def onStatusChanged_= (v: EventHandler[WebEvent[String]]) { onStatusChanged() = v}
    
  def onResized = engine.onResizedProperty
  def onResized_= (v: EventHandler[WebEvent[Rectangle2D]]) { onResized() = v}
      
  def onVisibilityChanged = engine.onVisibilityChangedProperty
  def onVisibilityChanged_= (v: EventHandler[WebEvent[java.lang.Boolean]]) { onVisibilityChanged() = v}
  
  def createPopupHandler = engine.createPopupHandlerProperty
  def createPopupHandler_= (v: Callback[PopupFeatures, WebEngine]) { createPopupHandler() = v}

  def confirmHandler = engine.confirmHandlerProperty
  def confirmHandler_= (v: Callback[String, java.lang.Boolean]) { confirmHandler() = v}
  
  def promptHandler = engine.promptHandlerProperty
  def promptHandler_= (v: Callback[PromptData, String]) { promptHandler() = v}
  
}